package com.weiqiao.api.until;

import com.weiqiao.api.domain.ApiResponseEntity;
import com.weiqiao.modules.basic.base.constant.e.BaseEnum;

/**
 * 构造Api返回值
 */
public class ApiResUtil {

    /**
     * 全参返回值
     *
     * @param code       模块编号
     * @param result     返回状态:true成功 false:失败
     * @param resultMsg  返回信息提示
     * @param resultData 返回数据
     * @return
     */
    public static ApiResponseEntity buildRes(BaseEnum code, boolean result, String resultMsg, Object resultData) {
        ApiResponseEntity apiResponseEntity = new ApiResponseEntity();
        apiResponseEntity.setCode(code.toString());
        apiResponseEntity.setResult(result);
        apiResponseEntity.setResultMsg(resultMsg);
        apiResponseEntity.setResultData(resultData);
        return apiResponseEntity;
    }


    /**
     * 缺省返回数据
     * 多用于只需要返回result结果
     *
     * @param code      模块编号
     * @param result    返回状态:true成功 false:失败
     * @param resultMsg 返回信息提示
     * @return
     */
    public static ApiResponseEntity buildRes(BaseEnum code, boolean result, String resultMsg) {
        ApiResponseEntity apiResponseEntity = new ApiResponseEntity();
        apiResponseEntity.setCode(code.toString());
        apiResponseEntity.setResult(result);
        apiResponseEntity.setResultMsg(resultMsg);
        return apiResponseEntity;
    }

    /**
     * 缺省模块编号、返回数据
     * 多用于只需要返回result结果
     *
     * @param result    返回状态:true成功 false:失败
     * @param resultMsg 返回信息提示
     * @return
     */
    public static ApiResponseEntity buildRes(boolean result, String resultMsg) {
        ApiResponseEntity apiResponseEntity = new ApiResponseEntity();
        apiResponseEntity.setResult(result);
        apiResponseEntity.setResultMsg(resultMsg);
        return apiResponseEntity;
    }

    /**
     * 缺省模块编号
     *
     * @param result    返回状态:true成功 false:失败
     * @param resultMsg 返回信息提示
     * @param resultData 返回数据
     * @return
     */
    public static ApiResponseEntity buildRes(boolean result, String resultMsg, Object resultData) {
        ApiResponseEntity apiResponseEntity = new ApiResponseEntity();
        apiResponseEntity.setResult(result);
        apiResponseEntity.setResultMsg(resultMsg);
        apiResponseEntity.setResultData(resultData);
        return apiResponseEntity;
    }

}
